function data = noinfnan(data, rv)
% noinfnan  - replace Inf/NaN's in input with replacement value
%
% FORMAT:       data = noinfnan(data [, rv])
%
% Input fields:
%
%       data        N-d single/double input
%       rv          replacement value (default: 0)
% Output fields:
%
%       data        data with amended content

% Version:  v0.7g
% Build:    9100717
% Date:     Oct-07 2009, 5:02 PM CEST
% Author:   Jochen Weber, SCAN Unit, Columbia University, NYC, NY, USA
% URL/Info: http://wiki.brainvoyager.com/BVQXtools

% argument check
if nargin < 2 || ...
   ~isnumeric(rv) || ...
    numel(rv) ~= 1
    rv = 0;
end

% replace bad values
data(isinf(data) | isnan(data)) = rv;
